<div id="app">
    <admin-page-header back>
        <bi-button type="primary" @click="handleEdit()">添加分组</bi-button>
    </admin-page-header>

    <div class="container">
        <div class="row">
            <div class="col-12">
                <bi-card title="分组列表">
                    <bi-table :data="list" :loading="loading" tree item-key="group_id"  :storagename="$user.getStorageName('admin-usergroup-list')" >
                        <bi-table-column label="ID"  name="group_id" width="50" ></bi-table-column>
                        <bi-table-column label="分组名称" tree-fold name="title" ></bi-table-column>
                        <bi-table-column label="管理" width="150"  v-slot="{row}" > 
                            <bi-button type="primary" @click="handleEdit(row)" :disabled="row.power=='ALL'" >编辑</bi-button>
                            <bi-button type="warning" @click="handleDel(row)" :disabled="row.power=='ALL'" >删除</bi-button>
                        </bi-table-column>
                    </bi-table>
                </bi-card>
            </div>
        </div>
    </div>
</div>

<script>
let app = admin.createApp({
    data(){
        return {
            list:[],
            loading:false,
        }
    },
    methods:{
        flash(){
            this.loading = true;
            this.$ajax({
                url:this.$url({action:'groupList'}),
                success:(res)=>{
                    this.list = res.list;
                },
                over:()=>{
                    this.loading = false;
                }
            })

        },
        handleEdit(item){

            let gets = {};

            if (item){
                gets.id= item.group_id;
            }

            this.$go({action:'groupEdit',gets});
        },
        handleDel(item){
            this.$confirm({text:'确定删除？',type:'warning'},()=>{
                this.$ajax({
                    url:this.$url({action:'groupDel'}),
                    data:{
                        group_id:item.group_id,
                    },
                    success:(res)=>{
                        this.$user.delLocalStorage('admin-user-group-input');
                        this.flash();
                        this.$toast({text:'删除成功',type:'success'});
                    }
                })
            })
        }
    },
    mounted(){
        this.flash();
    }
}).mount('#app');

</script>